<?php

class CompanyMessagesSent extends BaseEntity{

	public static $type = "CompanyMessagesSent";

	function __construct($id = 0){
		parent::__construct($id);
	}
	
	function wasSent($message, $user){
		$sql = "select * from CompanyMessagesSent where `companyMessageId` = ".$message->id." AND `userId` = ".$user->id;
		$result = $this->repository->fetchArray($sql);
		
		return (count($result) > 0);
	}
	
	function getSentMessages(User $user, $limit = null){
		return $this->search("`userId` = ".$user->id, "sendDate DESC", $limit);
	}
	
	static function markAsSent(CompanyMessages $message, User $user){
		$companyMessageSent = new CompanyMessagesSent();
		$companyMessageSent->companyMessageId = $message->id;
		$companyMessageSent->userId = $user->id;
		$companyMessageSent->sendDate = date("Y-m-d H:i:s");
		$companyMessageSent->save(false);
		return $companyMessageSent;
	}
}

?>
